/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import { signPersonMiniProgramDak } from '@/services/mini/aliapp';
import { ModalForm, ProFormText } from '@ant-design/pro-form';
import { Row, Typography } from 'antd';
import React from 'react';

const AliappBindDak: React.FC<{
  inn_account: string;
  auth_appid: string;
  reloadTable: () => void;
}> = (props) => {
  const { inn_account, auth_appid, reloadTable } = props;

  const title = `${!inn_account ? '绑定' : '修改'}驿站`;

  const onFinish = async (val: { inn_account: any }) => {
    const { inn_account: account } = val;

    const status = await signPersonMiniProgramDak({
      inn_account: account,
      auth_appid: auth_appid,
    });
    if (status) {
      reloadTable();
    }
    return status;
  };

  return (
    <ModalForm
      title={title}
      width={400}
      modalProps={{
        centered: true,
      }}
      trigger={<a>{title}</a>}
      layout='horizontal'
      onFinish={onFinish}
    >
      {inn_account && (
        <Row style={{ marginBottom: 20 }}>
          <Typography.Text strong>驿站账号: {inn_account}</Typography.Text>
        </Row>
      )}
      <ProFormText
        name='inn_account'
        label={!inn_account ? '驿站账号' : '新账号'}
        placeholder='请输入驿站账号'
        rules={[{ required: true, message: '请输入驿站账号' }]}
      />
    </ModalForm>
  );
};

export default AliappBindDak;
